package servlets;

import java.io.*;
import java.util.*;

import javax.servlet.*;
import javax.servlet.http.*;

import controller.ItemController;

import model.Item;
import dao.*;

/**
 * An HTTP Servlet that overrides the service method to return a simple web
 * page.
 */
public class WaimaiStoreServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void init() throws ServletException {

	}

	public void destroy() {

	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) {
		doGet(request, response);
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response) {
		ArrayList<Item> list = ItemController.getAllItems();
		request.setAttribute("itemList", list);

		RequestDispatcher rd = request.getRequestDispatcher("/home.jsp");
		try {
			rd.forward(request, response);
		} catch (ServletException | IOException e) {
			e.printStackTrace();
		}
	}

}
